package org.ms.springcloud.hystrix.consumer.isolation;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import org.ms.springcloud.hystrix.consumer.fallbackFeignClient.UserFeignClient;
import org.ms.springcloud.service.api.User;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Random;

@RestController
public class OrderController {

    private final Random rnd = new Random(System.currentTimeMillis());

    @GetMapping("/order/user/{id}")
    @HystrixCommand(fallbackMethod = "findOrderFallback", commandProperties = {
            @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "1000")
    })
    public String findOrder(@PathVariable("id") Long id) throws InterruptedException {
        Thread.sleep(rnd.nextInt(2000));
        System.out.println("findOrder:"+id);
        return "查找订单成功";
    }

    public String findOrderFallback(Long id) {
        return "订单查找失败！";
    }

}